import { InitFlow } from "./base_frame/InitFlow";
import { ShaderMgr } from "./base_frame/ShaderMgr";
import { BaseCamera } from "./base_frame/BaseCamera";
import { CameraDemo } from "./chaper07/CameraDemo";
import { CameraEmulator } from "./chaper07/CameraEmulator";
import { CameraOrthoEmulator } from "./chaper07/CameraOrthoEmulator";
import { CameraPerspectiveEmulator } from "./chaper07/CameraPerspectiveEmulator";
import { CameraPerspectiveEmulatorResolve } from "./chaper07/CameraPerspectiveEmulatorResolve";
import { DrawElement } from "./chaper07/DrawElement";
import { TestFlow } from "./chaper_test/TestFlow";
import { LightCube } from "./chaper08/LightCube";
import { IShaderBase } from "./base_frame/IShaderBase";
import { ShaderBase } from "./base_frame/ShaderBase";
import { LightCubeBase } from "./chaper08/LightCubeBase";
import { PointLightCube } from "./chaper08/PointLightCube";
import { LightCube02 } from "./chaper08/LightCube02";
import { PointLightSphere } from "./chaper08/PointLightSphere";
import { PointLightSphere02 } from "./chaper08/PointLightSphere02";
import { FogDemo } from "./chaper10/FogDemo";
import { TextureCube } from "./chaper10/TextureCube";
import { FrameBufferPanel } from "./chaper10/FrameBufferPanel";
import { Panel } from "./chaper10/Panel";
import { TextureCubeCommon } from "./chaper10/TextureCubeCommon";
import { OutLine } from "./chaper10/OutLine";

export class Main {

    constructor(inputBlur: Function) {

        new InitFlow().init();

        new TestFlow();

        this.__init__();
        
        var input = document.getElementById("input_id") as HTMLInputElement;
        //@ts-ignore
        input.onblur = inputBlur.bind(this, ShaderMgr.camera);
        update(0);

        function update(time: number): void {
            ShaderMgr.render();
            requestAnimationFrame(update);
        }
    }

    __init__() {
        // 注册执行流程
        // ShaderMgr.regShader(CameraEmulator);
        // ShaderMgr.regShader(CameraOrthoEmulator);
        // ShaderMgr.regShader(CameraPerspectiveEmulatorResolve);
        // ShaderMgr.regShader(CameraDemo);
        // ShaderMgr.regShader(CameraPerspectiveEmulator);
        var camera = ShaderMgr.regShader(BaseCamera);
        ShaderMgr.camera = camera;
        // ShaderMgr.regShader(DrawElement);
        // ShaderMgr.regShader(LightCube);
        // ShaderMgr.regShader(LightCubeBase);
        // ShaderMgr.regShader(LightCube02);
        // ShaderMgr.regShader(PointLightCube);
        // !!  这里有在顶点着色器里面处理颜色
        // ShaderMgr.regShader(PointLightSphere);
        // !!  这里有在片元着色器里面处理颜色
        // ShaderMgr.regShader(PointLightSphere02);
        // ShaderMgr.regShader(FogDemo);
        // ShaderMgr.regShader(TextureCube);
        // ShaderMgr.regShader(FrameBufferPanel);
        // ShaderMgr.regShader(Panel);
        // ShaderMgr.regShader(TextureCubeCommon);
        ShaderMgr.regShader(OutLine);
    }




}

new Main(inputBlur);
//@ts-ignore
window.inputBlur = inputBlur;

function inputBlur(shader: any, ev: InputEvent,) {
    console.log(ev);
    if (ev.data) {
        if (shader && shader.inputBlur) {
            shader.inputBlur(ev.data);
        }
    }
}